#ifndef THREADMANAGER_H
#define THREADMANAGER_H

#include <iostream>
#include <map>
#include <pthread.h>
using namespace std;

#include "Tool.h"
#include "InfoContainer.h"
#include "SerialPort.h"
#include "DataCollect.h"
#include "WeiBo.h"
#include "SmartMode.h"
#include "TerminalControl.h"
#include "DataBase.h"
#include "CmdTransfer.h"

class CThreadManager
{
private:
    struct threadParameter1
    {
        pthread_mutex_t ComLock;
        CDataCollect * DataCollect;
        int CollectFlag;
        int TerminalFlag;
    };

    struct threadParameter2
    {
        CWeiBo * WeiBo;
        CWeiQueue * WeiQueue;
    };

public:
    CThreadManager();
    ~CThreadManager();

    bool Init(); //对串口初始化
    bool Run();
    void Cleanup();
    void *DataCollectThread( void *arg );
    void *ListenWeiBoThread( void *arg );

private:
    bool MainControlerThread();
    bool StopThread();

private:
    pthread_t DataCollectThreadID;
    pthread_t ListenWeiBoThreadID;
    threadParameter1 Tp1;
    threadParameter2 Tp2;
    bool threadEnable1;
    bool threadEnable2;

    CTool * Tool;
    CSerialPort * SerialPort;
    CInfoContainer * InfoContainer;
    CDataBase * Database;

    CQueue * Queue;

    CSmartMode * SmartMode;
    CTerminalControl * TerminalControl;
    CCmdTransfer * CmdTransfer;

    int * RoomFlag; //每个房间都有一个SmartFlag

};

//-----------------------------------
// Function Prototypes
//-----------------------------------
static void *DataCollectThreadFunc( void * arg);
static void *ListenWeiBoThreadFunc( void * arg);

//-----------------------------------
//Global Variables
//-----------------------------------
static CThreadManager *DataCollectHandle = 0;
static CThreadManager *ListenWeiBoHandle = 0;

#endif // THREADMANAGER_H
